﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccessLayer.Reports;
using DataAccessLayer.Visit;
using ModelLayer.Reports;
using System.Data;
using MedicalDictationView;

namespace ControllerLayer.Reports
{
    public class ReportsController
    {
        public static DataTable table = new DataTable();
        public static MainIU dictationIU;


        public static void InsertNewDictation(string accessionNumber,string path, string AuthorOID )
        {
            Report report = new Report();
            report.ProcedureOID = VisitDataAccess.GetProcedureOIDFromAccessionNumber(accessionNumber);
            report.Type = 1; // tipo Dictado

            table = GetIndexOfReportPart(1, ReportDataAccess.GetReportOIDOfProcedureOID(report.ProcedureOID)); // Relacion 1
            if (table.Rows.Count == 0)
                report.Relation = 1;
            else
                report.Relation = table.Rows.Count + 1;
            
            report.Path = path;

            report.Author = AuthorOID;

            report.CreationTime = DateTime.Now;

            ReportDataAccess.InsertNewDictation(report);
 
        }

        public static DataTable GetIndexOfReportPart(int version, Guid ReportOID)
        {
            return VisitDataAccess.GetIndexOfReportPart(version, ReportOID);
        }

        public static Guid GetProcedureOIDFromAccessionNumber(string accessionNumber)
        {
            return VisitDataAccess.GetProcedureOIDFromAccessionNumber(accessionNumber);
        }

        public static Guid GetReportOIDFromProcedureOID(Guid procedureOID)
        {
            return ReportDataAccess.GetReportOIDOfProcedureOID(procedureOID);
        }

        public static void UpdateDictation(Guid reportPartOID, string status)
        {
            ReportDataAccess.UpdateStatusOfDictations(reportPartOID,status);
        }

        public static void DeleteDictation(Guid reportPartOID, string status, Guid reportOID_, int index)
        {
            ReportDataAccess.DeleteDictation(reportPartOID, status, reportOID_, index);
        }

        public static void RejectInform(Guid ReportPartOID_, string status, string reason)
        {
            ReportDataAccess.RejectInform(ReportPartOID_,status,reason);
        }

        public static string GetPathOfReportPartOid(Guid ReportPartOID)
        {
            return ReportDataAccess.GetPathOfReportPartOid(ReportPartOID);
        }

        public static DataTable GetRadiologists()
        {
            return ReportDataAccess.GetRadiologists();
        }

        public static DataTable GetModalities()
        {
            return ReportDataAccess.GetModalities();
        }

        public static DataTable GetPatientsTable(string lastName, string name, string pid, string assignedPractitioner, string modality)
        {
            return ReportDataAccess.GetPatientsTable(lastName, name, pid, assignedPractitioner, modality);
        }

        public static DataTable GetPatientsTableWithDate(string lastName, string name, string pid, string assignedPractitioner, string modality, string date)
        {
            return ReportDataAccess.GetPatientsTableWithDate(lastName, name, pid, assignedPractitioner, modality, DateTime.Parse(date));
        }
    }
}
